//
//  EditInfoViewController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/10.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "EditInfoViewController.h"
#import "BaseTextField.h"

@interface EditInfoViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet BaseTextField *input;
@property (weak, nonatomic) IBOutlet UILabel *textLimit;

@end

@implementation EditInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)setupUI{
    [super setupUI];
    self.title = self.pageTitle;
    self.input.placeholder = self.plhText;
    self.input.placeholderColor = PlhColor;
    self.textLimit.hidden = !(self.countLimit > 0);
    self.textLimit.text = [NSString stringWithFormat:@"0/%@",@(self.countLimit)];
   
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    [self performSelector:@selector(configLimit) withObject:nil afterDelay:0.05];
    return YES;
}

- (void)configLimit{
    if (self.countLimit <= 0) {
        return;;
    }
    NSString *curText = self.input.text;
    if (curText.length > self.countLimit) {
        curText = [curText substringToIndex:self.countLimit];
        self.input.text = curText;
    }
    self.textLimit.text = [NSString stringWithFormat:@"%@/%@",@(self.input.text.length),@(self.countLimit)];
    
}
- (IBAction)doneAction:(id)sender {
    if (!self.input.text.length) {
        LCInfoHUD(self.plhText, 1);
        return;
    }
    if (self.actionBlock) {
        self.actionBlock(1, self.input.text);
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
